import React from 'react';
import { Select } from 'antd';

const { Option } = Select;

export function generateSelect(key, dictMap) {
  const dictList = dictMap[key];
  if (!dictList) return '';
  return dictList.map((dict) => (
    <Option key={dict.id} value={dict.code}>
      {dict.value}
    </Option>
  ));
}

export function generateSelectForObj(dictList) {
  let list = [];
  if (dictList) {
    for (var item in dictList) {
      let newItem = {};
      newItem.id = item;
      newItem.value = dictList[item];
      list.push(newItem);
    }
  }
  return list.map((item) => {
    return <Select.Option key={item.id}>{`${item.value}`}</Select.Option>;
  });
}

export function showWaringValue(key, dictMap, value) {
  const values = dictMap[key];
  if (!values) return '';
  let text = '';
  values.forEach((item) => {
    if (item.value === value) text = item.keyDesc;
  });
  return text;
}

export function showValue(key, dictMap, value) {
  const values = dictMap[key];
  if (!values) return '';
  let text = '';
  values.forEach((item) => {
    if (item.code === value) text = item.value;
  });
  return text;
}

export function showEtfValue(key, dictMap, value) {
  const values = dictMap[key];
  if (!values) return '';
  let text = '';

  for (let key in values) {
    if (key == value) {
      text = values[key];
    }
  }
  return text;
}

export function showValueForObj(dictMap, value) {
  let newvalue = typeof value == 'string' ? value.split(',') : value;
  if (!value) return '';
  let text = '';
  for (var item in dictMap) {
    newvalue.map((element) => {
      if (element === item) {
        text += dictMap[item] + ' ';
      }
    });
  }
  return text;
}

export function showValue2(key, dictMap, value) {
  const values = dictMap[key];
  if (!values) return '';
  let text = '';
  values.forEach((item) => {
    if (item.value === value) text = item.keyDesc;
  });
  return text;
}

export const bondColumns = [
  {
    title: '债券代码',
    dataIndex: 'tradingCode',
    key: 'tradingCode',
    width: 85,
  },
  {
    title: '债券简称',
    dataIndex: 'secuabbr',
    key: 'secuabbr',
    width: 130,
  },
  {
    title: '交易市场',
    dataIndex: 'exchangeName',
    key: 'exchangeName',
  },
  {
    title: '当前持仓',
    dataIndex: 'currentAmount',
    key: 'currentAmount',
    render: (text) => (!text ? '' : `${text}`.replace(/\B(?=(\d{3})+(?!\d))/g, ',')),
  },
  {
    title: '票面总额',
    dataIndex: 'parValueTotal',
    key: 'parValueTotal',
    render: (text) => (!text ? '' : `${text}`.replace(/\B(?=(\d{3})+(?!\d))/g, ',')),
  },
  {
    title: '上市日期',
    dataIndex: 'listingDate',
    key: 'listingDate',
    width: 100,
  },
  {
    title: '退市日期',
    dataIndex: 'delistingDate',
    key: 'delistingDate',
    width: 100,
  },
  {
    title: '起息日期',
    dataIndex: 'accruedDate',
    key: 'accruedDate',
    width: 100,
  },
  {
    title: '到期日期',
    dataIndex: 'endDate',
    key: 'endDate',
    width: 100,
  },
  {
    title: '票面利率(%)',
    dataIndex: 'couponRate',
    key: 'couponRate',
    width: 100,
  },
  {
    title: '发行人',
    dataIndex: 'issuer',
    key: 'issuer',
  },
  {
    title: '当前余额',
    dataIndex: 'changeIssuesize',
    key: 'changeIssuesize',
  },
  {
    title: '剩余本金',
    dataIndex: 'sybj',
    key: 'sybj',
  },
  {
    title: '计息方式',
    dataIndex: 'interestMethod',
    key: 'interestMethod',
  },
  {
    title: '付息方式',
    dataIndex: 'paymentMethod',
    key: 'paymentMethod',
  },
  {
    title: '债券期限(年)',
    dataIndex: 'bondMaturity',
    key: 'bondMaturity',
  },
  {
    title: '债项评级',
    dataIndex: 'ratingCode',
    key: 'ratingCode',
  },
  {
    title: '主体评级',
    dataIndex: 'creditRating',
    key: 'creditRating',
  },
  {
    title: '中债估值净价',
    dataIndex: 'netValuation',
    key: 'netValuation',
  },
  {
    title: '中债估值全价',
    dataIndex: 'fullValuationFinal',
    key: 'fullValuationFinal',
  },
  {
    title: '中债估值收益率',
    dataIndex: 'evalutedYield',
    key: 'evalutedYield',
  },
  {
    title: '中证估值净价',
    dataIndex: 'zzNetValuation',
    key: 'zzNetValuation',
  },
  {
    title: '中证估值全价',
    dataIndex: 'zzFullValuationFinal',
    key: 'zzFullValuationFinal',
  },
  {
    title: '中证估值收益率',
    dataIndex: 'zzEvalutedYield',
    key: 'zzEvalutedYield',
  },
  {
    title: '应计利息',
    dataIndex: 'accruedInterestFinal',
    key: 'accruedInterestFinal',
  },
  {
    title: '发行面额(亿元)',
    dataIndex: 'issueSize',
    key: 'issueSize',
  },
  {
    title: '债券一级分类',
    dataIndex: 'categoryNamei',
    key: 'categoryNamei',
  },
  {
    title: '债券二级分类',
    dataIndex: 'categoryNameii',
    key: 'categoryNameii',
  },
  {
    title: '利率债信用债',
    dataIndex: 'rateOrCredit',
    key: 'rateOrCredit',
  },
  {
    title: '麦考林久期',
    dataIndex: 'duration',
    key: 'duration',
  },
  {
    title: '修正久期',
    dataIndex: 'modiDuration',
    key: 'modiDuration',
  },
  {
    title: '凸性',
    dataIndex: 'convexity',
    key: 'convexity',
  },
];

export const stkColumns = [
  {
    title: '股票代码',
    dataIndex: 'tradingCode',
    key: 'tradingCode',
  },
  {
    title: '股票名称',
    dataIndex: 'secuabbr',
    key: 'secuabbr',
  },
  {
    title: '交易市场',
    dataIndex: 'exchangeName',
    key: 'exchangeName',
  },
  {
    title: '持仓数量',
    dataIndex: 'currentAmount',
    key: 'currentAmount',
    render: (text) => (!text ? '' : `${text}`.replace(/\B(?=(\d{3})+(?!\d))/g, ',')),
  },
  {
    title: '持仓成本',
    dataIndex: 'costPrice',
    key: 'costPrice',
  },
  {
    title: '浮动盈亏',
    dataIndex: 'enFloatProfit',
    key: 'enFloatProfit',
  },
  {
    title: '最新价/今收盘价',
    dataIndex: 'enLastPrice',
    key: 'enLastPrice',
  },
  {
    title: '持仓市值',
    dataIndex: 'marketValue',
    key: 'marketValue',
    render: (text) => (!text ? '' : `${text}`.replace(/\B(?=(\d{3})+(?!\d))/g, ',')),
  },
  {
    title: '一级行业',
    dataIndex: 'findunName',
    key: 'findunName',
  },
  {
    title: '二级行业',
    dataIndex: 'sinduName',
    key: 'sinduName',
  },
];
